<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改房间流水')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-tRoomBill-edit" th:object="${tRoomBill}">
            <input id="id" name="id" th:field="*{id}"  type="hidden">
			<div class="form-group">	
				<label class="col-sm-3 control-label">房间号：</label>
				<div class="col-sm-3">
					<input id="fjh" name="fjh" th:field="*{fjh}" disabled class="form-control" type="text">
				</div>
				<label class="col-sm-3 control-label">状态：</label>
				<div class="col-sm-3">
					<input id="zt" name="zt" th:field="*{zt}" disabled class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">开始时间：</label>
				<div class="col-sm-3">
					<input id="kssj" name="kssj" th:field="*{kssj}" disabled class="form-control" type="text">
				</div>
				<label class="col-sm-3 control-label">基础费用：</label>
				<div class="col-sm-3">
					<input id="jcfy" name="jcfy" th:field="*{jcfy}" disabled class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">香烟：</label>
				<div class="col-sm-2">
					<input id="xyfy" name="xyfy" th:field="*{xyfy}" disabled  class="form-control" type="text">
				</div>
				<table  >
					<tr >
						<td  style="width: 10%; text-align: center; line-height: 20px;  " th:each="s:${xyDictList}">
						     <button type="button" th:onclick="xyylSave([[${s.dictCode}]],[[${s.dictValue}]],1,'xy',[[${s.dictLabel}]])"   ondblclick="" th:text="${s.dictLabel}"></button>
						     <span th:id="'xy' + ${s.dictCode}"  th:onclick="xyylSave([[${s.dictCode}]],-[[${s.dictValue}]],-1,'xy',[[${s.dictLabel}]])"  th:text="${s.sl}"></span>
						</td>
					</tr>
				</table>
				
			</div>
			
			<div class="form-group">	
				<label class="col-sm-3 control-label">零食饮料：</label>
				<div class="col-sm-2">
					<input id="ylfy" name="ylfy" th:field="*{ylfy}" disabled class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label"></label>
				<table  >
					<tr >
						<td  style="width: 7%; text-align: center; line-height: 20px;  " th:each="s:${ylDictList}">
						     <button type="button" th:onclick="xyylSave([[${s.dictCode}]],[[${s.dictValue}]],1,'yl',[[${s.dictLabel}]])"   ondblclick="" th:text="${s.dictLabel}"></button>
						     <span th:id="'yl' + ${s.dictCode}"  th:onclick="xyylSave([[${s.dictCode}]],-[[${s.dictValue}]],-1,'yl',[[${s.dictLabel}]])"  th:text="${s.sl}"></span>
						</td>
						
					</tr>
				</table>
			</div>
			
			
			<div class="form-group">
			
				<label class="col-sm-3 control-label">超时费用：</label>
				<div class="col-sm-3">
					<input id="csfy" name="csfy" th:field="*{csfy}" th:onkeyup="changeZfy()" class="form-control" type="text">
				</div>
			</div>
			
			<div class="form-group">	
				<label class="col-sm-3 control-label">总金额：</label>
				<div class="col-sm-3">
					<input id="zfy" name="zfy" th:field="*{zfy}" disabled class="form-control" type="text">
				</div>
			</div>
		</form>
    </div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "web/tRoomBill";
		$("#form-tRoomBill-edit").validate({
			rules:{
				xxxx:{
					required:true,
				},
			},
			focusCleanup: true
		});
		
		function submitHandler() {
			var id = $("#id").val();
			var time2 = new Date().Format("yyyy-MM-dd hh:mm:ss"); 
			var fjh = $("#fjh").val();
			
        	var config = {
       	        url: "/web/tRoomBill/edit4",
       	        type: "post",
       	        dataType: "json",
       	        data: {
       	        	id:id,
       	        	fjh:fjh,
       	        	zt:"结账",
       	        	jssj:time2
       	        },
       	        beforeSend: function () {
       	        	$.modal.loading("正在处理中，请稍后...");
       	        	$.modal.disable();
       	        },
       	        success: function(result) {
       	        	if (typeof callback == "function") {
       	        	    callback(result);
       	        	}
       	        	$.operate.successCallback(result);
       	        }
       	    };
       	    $.ajax(config)
	         
	    }
		
		function xyylSave(dictCode,dictValue,zjsl,lx,mc){
			var oldXyfy = $("#"+lx+"fy").val();//获取当前香烟费用
			var newXyfy = accAdd(oldXyfy, dictValue);//计算新增后费用
			if(newXyfy<0){
				$.modal.alertWarning("错误的操作");
				return;
			}
			
			var oldXysl = $("#"+lx+dictCode).text();//获取当前香烟数量
			var newXysl = accAdd(oldXysl,zjsl) ;//当前香烟数量加1
			if(newXysl<0){
				$.modal.alertWarning("错误的操作");
				return;
			}
			
			$("#"+lx+dictCode).text(newXysl)//更新香烟数量
			$("#"+lx+"fy").val(newXyfy)//更新香烟费用
			
			
			//计算总费用
			var jcfy = $("#jcfy").val();//基础费用
			var xyfy = $("#xyfy").val();//香烟费用
			var ylfy = $("#ylfy").val();//香烟费用
			var csfy = $("#csfy").val();//香烟费用
			
			var zfy1 = accAdd(jcfy, xyfy);
			var zfy2 = accAdd(ylfy, csfy);
			var zfy = accAdd(zfy1,zfy2);
			$("#zfy").val(zfy );
			
			var id = $("#id").val();
			
			//保存记录房间记录
			$.ajax({
				url: "/web/tRoomBill/edit3",
				data: 
				{id:id,
				 xyfy:xyfy,
				 ylfy:ylfy,
				 csfy:csfy,
				 zfy:zfy
				},
				cache: false,
				type: 'POST',
				dataType: "json",
				success: function (result) {
				}
			});
			
			var fjh = $("#fjh").val();
			
			
			//保存香烟饮料记录
			$.ajax({
				url: "/web/tXyBill/add",
				data: 
				{roomBillId:id,
				 fjh:fjh,
				 dictCode:dictCode,
				 mc,mc,
				 jg:Math.abs(dictValue),
				 sl:newXysl,
				 lx:lx
				},
				cache: false,
				type: 'POST',
				dataType: "json",
				success: function (result) {
				}
			});
			
			
		}
		
		function changeZfy(){
			//计算总费用
			var jcfy = $("#jcfy").val();//基础费用
			var xyfy = $("#xyfy").val();//香烟费用
			var ylfy = $("#ylfy").val();//香烟费用
			var csfy = $("#csfy").val();//香烟费用
			
			var zfy1 = accAdd(jcfy, xyfy);
			var zfy2 = accAdd(ylfy, csfy);
			var zfy = accAdd(zfy1,zfy2);
			$("#zfy").val(zfy );
			
			var id = $("#id").val();
			//保存记录
			$.ajax({
				url: "/web/tRoomBill/edit3",
				data: 
				{id:id,
				 xyfy:xyfy,
				 ylfy:ylfy,
				 csfy:csfy,
				 zfy:zfy
				},
				cache: false,
				type: 'POST',
				dataType: "json",
				success: function (result) {
				}
			});
			
		}
		
		Date.prototype.Format = function (fmt) { // author: meizz
		    var o = {
		        "M+": this.getMonth() + 1, // 月份
		        "d+": this.getDate(), // 日
		        "h+": this.getHours(), // 小时
		        "m+": this.getMinutes(), // 分
		        "s+": this.getSeconds(), // 秒
		        "q+": Math.floor((this.getMonth() + 3) / 3), // 季度
		        "S": this.getMilliseconds() // 毫秒
		    };
		    if (/(y+)/.test(fmt))
		        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
		    for (var k in o)
		        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
		            return fmt;
		}
		
	</script>
</body>
</html>
